﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HXDNB.DAL
{
    public class BuyOrderBLL : BaseDAL<BuyOrder>
    {
        public BuyOrderBLL() : base("BuyOrder") { }

        public Dictionary<int, List<BuyOrderList>> GetInfoList(List<int> Ids)
        {
            var list = (from i in _e.BuyOrder
                        join j in _e.Product on i.ProductID equals j.ID into Temp
                        from t in Temp.DefaultIfEmpty()
                        where Ids.Contains(i.ParentID ?? 0)
                        orderby i.Createtime descending
                        select new BuyOrderList
                        {
                            ID = i.ID,
                            AllPrice = i.AllPrice,
                            Createtime = i.Createtime,
                            Express = i.Express,
                            ExpressPrice = i.ExpressPrice,
                            Num = i.Num,
                            OtherPrice = i.OtherPrice,
                            Price = i.Price,
                            ProductID = i.ProductID,
                            ProductName = t.ProductName,
                            ReceivedTime = i.ReceivedTime,
                            Remarks = i.Remarks,
                            SendTime = i.SendTime,
                            State = i.State,
                            Discount = i.Discount,
                            ParentID = i.ParentID,
                            ShipTime = i.ShipTime
                        }).ToList();
            Dictionary<int, List<BuyOrderList>> result = new Dictionary<int, List<BuyOrderList>>();
            foreach (int item in Ids)
            {
                List<BuyOrderList> lists = list.Where(i => i.ParentID == item).ToList();
                result.Add(item, lists);
            }
            return result;
        }
        public List<BuyOrder> GetInfoByParentID(int PatentID)
        {
            var info = from i in _e.BuyOrder
                       where i.ParentID == PatentID
                       select i;
            return info.ToList();
        }
    }
}
